package com.cryptoneedle.garden.entity.source.metadata;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.garden.enums.SourceCollectFrequency;
import com.cryptoneedle.garden.enums.SourceConnectType;
import com.cryptoneedle.garden.enums.SourceDatabaseType;
import com.cryptoneedle.garden.key.source.metadata.JdbcKey;
import com.cryptoneedle.garden.key.source.metadata.ServerKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

/**
 * <p>description: 源数据源-目录 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-19
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "source_catalog", uniqueConstraints = @UniqueConstraint(name = "uk_source_catalog_source_system_code", columnNames = {"transformSystemCode"}))
@Comment("源数据源-目录")
public class SourceCatalog extends BaseEntity {

    @Id
    @Comment("源数据源-目录名称")
    private String catalogName;

    @Comment("服务器-主机")
    private String host;
    @Comment("服务器-端口")
    private Integer port;

    @Enumerated(EnumType.STRING)
    @Comment("JDBC-数据库类型")
    private SourceDatabaseType databaseType;
    @Comment("JDBC-路径")
    private String route;
    @Comment("JDBC-用户名称")
    private String userName;
    @Comment("JDBC-密码")
    private String password;
    @Enumerated(EnumType.STRING)
    @Comment("JDBC-连接类型")
    private SourceConnectType connectType;
    @Comment("JDBC-驱动类")
    private String driverClass;
    @Comment("JDBC-连接地址")
    private String url;
    @Column(length = 4000)
    @Comment("JDBC-数据库版本")
    private String databaseVersion;

    @Comment("源数据源-Doris目录编码")
    private String dorisCatalogName;
    @Comment("源数据源-默认系统编码")
    private String defaultSystemCode;
    @Comment("源数据源-默认采集频率")
    @Enumerated(EnumType.STRING)
    private SourceCollectFrequency defaultCollectFrequency;
    @Comment("源数据源-启用目录")
    private Boolean enabled;

    @Comment("服务器-可连接")
    private Boolean serverConnected;
    @Comment("服务器-最后可连接时间")
    private Date serverConnectedDt;
    @Comment("JDBC-可连接")
    private Boolean jdbcConnected;
    @Comment("JDBC-最后可连接时间")
    private Date jdbcConnectedDt;
    @Comment("DORIS-可连接")
    private Boolean dorisConnected;
    @Comment("DORIS-最后可连接时间")
    private Date dorisConnectedDt;

    /**
     * Key
     */

    public ServerKey serverKey() {
        return BeanUtil.copyProperties(this, ServerKey.class);
    }

    public JdbcKey jdbcKey() {
        return BeanUtil.copyProperties(this, JdbcKey.class);
    }

    public String catalogKey() {
        return this.catalogName;
    }

    /**
     * 其他
     */

    public String inetAddress() {
        return this.host + ":" + this.port;
    }
}
